import React from 'react'
import MenunConfig from '../../resource/menus'
import { Menu } from 'antd';
import { Link } from 'react-router-dom'
import './index.less'
const { SubMenu } = Menu;
export default class NavLeft extends React.Component {

  UNSAFE_componentWillMount() {
    const menuTreeNode = this.renderMenu(MenunConfig)
    this.setState({
      menuTreeNode
    })
  }

  //左侧菜单递归
  renderMenu = (data) => {
    return data.map(item => {
      if (item.children) {
        return (
          <SubMenu title={item.title} key={item.key}>
            {this.renderMenu(item.children)}
          </SubMenu>
        )
      }
      return <Menu.Item title={item.title} key={item.key}>
        <Link to={item.key}> {item.title}</Link>
      </Menu.Item>
    })
  }

  render() {
    return (
      <div>
        <div className="logo">
          <img src="/assets/logo-ant.svg" alt=""/>
          <h1>后台管理平台</h1>
        </div>
        <Menu theme="dark">
          {this.state.menuTreeNode}
        </Menu>
      </div>
    )
  }
}